Skip to content

feat: add workspace/didChangeWatchedFiles support#1408

Merged
sebthom merged 1 commit intoeclipse-lsp4e:mainfrom
sebthom:issue-547
Nov 20, 2025
Merged

feat: add workspace/didChangeWatchedFiles support#1408
sebthom merged 1 commit intoeclipse-lsp4e:mainfrom
sebthom:issue-547

Conversation

@sebthom
Copy link
Copy Markdown
Member

@sebthom sebthom commented Nov 18, 2025

Fixes #547

@sebthom
Copy link
Copy Markdown
Member Author

sebthom commented Nov 18, 2025

@angelozerr can you please check if this is what you need? You can download an update site with this PR from https://github.com/eclipse-lsp4e/lsp4e/actions/runs/19482961536/artifacts/4607414883

@angelozerr
Copy link
Copy Markdown
Contributor

@sebthom I would like to share my experience with this feature that I have implemented in LSP4IJ.

I suggest really that you support glob pattern to avoid having performance problem with language servers which receive some non expected files.

Supporting glob pattern is not trivial. I think you could use a lot of code I have written for IJ in https://github.com/redhat-developer/lsp4ij/tree/main/src/main/java/com/redhat/devtools/lsp4ij/features/files

You can find tests at https://github.com/redhat-developer/lsp4ij/tree/main/src/test/java/com/redhat/devtools/lsp4ij/features/files (which are the same than vscode)

The main idea is to work with https://github.com/redhat-developer/lsp4ij/blob/main/src/main/java/com/redhat/devtools/lsp4ij/features/files/watcher/FileSystemWatcherManager.java

See registration of watcher at https://github.com/redhat-developer/lsp4ij/blob/96db3b209cc09393af638bc1ff5b1ec92a2adb6c/src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java#L949

@angelozerr
Copy link
Copy Markdown
Contributor

@sebthom I am sorry https://github.com/jbosstools/jbosstools-quarkus has been give up, I will not have time to test your PR

Comment thread org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServerWrapper.java Outdated
Comment thread org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServerWrapper.java Outdated
@sebthom sebthom marked this pull request as draft November 19, 2025 06:36
@sebthom
Copy link
Copy Markdown
Member Author

sebthom commented Nov 19, 2025

@angelozerr I am trying to integrate the files from lsp4ji as you suggested. Can we normalize the license header to the style that is used in all files of LSP4E?

LSP4E license header style:

/*******************************************************************************
 * Copyright (c) <YEAR> Red Hat Inc. and others.
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *  <AUTHOR> (Red Hat Inc.) - initial implementation
 *******************************************************************************/

The LSP4IJ project seems to use slightly different license headers in different files:

https://github.com/redhat-developer/lsp4ij/blob/96db3b209cc09393af638bc1ff5b1ec92a2adb6c/src/main/java/com/redhat/devtools/lsp4ij/features/files/watcher/FileSystemWatcherManager.java

/*******************************************************************************
 * Copyright (c) 2024 Red Hat, Inc.
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v2.0 which accompanies this distribution,
 * and is available at https://www.eclipse.org/legal/epl-v20.html
 *
 * Contributors:
 * Red Hat, Inc. - initial API and implementation
 *******************************************************************************/
class FileSystemWatcherManager

https://github.com/redhat-developer/lsp4ij/blob/96db3b209cc09393af638bc1ff5b1ec92a2adb6c/src/main/java/com/redhat/devtools/lsp4ij/features/files/PathPatternMatcher.java

/*******************************************************************************
 * Copyright (c) 2019 Red Hat Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v20.html
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Red Hat Inc. - initial API and implementation
 *******************************************************************************/
class PathPatternMatcher

I would like to avoid having a zoo of unicorn copyright statements in LSP4E.

@mickaelistria maybe you can also say something about this?

@angelozerr
Copy link
Copy Markdown
Contributor

@angelozerr I am trying to integrate the files from lsp4ji as you suggested.

I am supper happy that you like the idea to use my code, That's great!

Can we normalize the license header to the style that is used in all files of LSP4E?

It is my code, so for me I have no problem that you do any change. If license allows that, feel free to change anything.

LSP4E license header style:

/*******************************************************************************
 * Copyright (c) <YEAR> Red Hat Inc. and others.
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *  <AUTHOR> (Red Hat Inc.) - initial implementation
 *******************************************************************************/

The LSP4IJ project seems to use slightly different license headers in different files:

https://github.com/redhat-developer/lsp4ij/blob/96db3b209cc09393af638bc1ff5b1ec92a2adb6c/src/main/java/com/redhat/devtools/lsp4ij/features/files/watcher/FileSystemWatcherManager.java

/*******************************************************************************
 * Copyright (c) 2024 Red Hat, Inc.
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v2.0 which accompanies this distribution,
 * and is available at https://www.eclipse.org/legal/epl-v20.html
 *
 * Contributors:
 * Red Hat, Inc. - initial API and implementation
 *******************************************************************************/
class FileSystemWatcherManager

https://github.com/redhat-developer/lsp4ij/blob/96db3b209cc09393af638bc1ff5b1ec92a2adb6c/src/main/java/com/redhat/devtools/lsp4ij/features/files/PathPatternMatcher.java

/*******************************************************************************
 * Copyright (c) 2019 Red Hat Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v20.html
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Red Hat Inc. - initial API and implementation
 *******************************************************************************/
class PathPatternMatcher

I would like to avoid having a zoo of unicorn copyright statements in LSP4E.

@mickaelistria maybe you can also say something about this?

@sebthom
Copy link
Copy Markdown
Member Author

sebthom commented Nov 19, 2025

@angelozerr nice! What about the year 2019 in PathPatternMatcher. Was this a copy and paste error, or is this really an old file from six years ago?

@angelozerr
Copy link
Copy Markdown
Contributor

No it is an old file that I have written for lemminx if I remember.

@angelozerr
Copy link
Copy Markdown
Contributor

@sebthom an another point which is very important is that your resource listener can be called a lot of time for instance if you get a lot of files from git.

Perhaps it is not the case with eclipse but with IJ it was the case. But keep in mind that your listener can be called a lot of time with a lot of files.

In this case the glob pattern support that I have written which use Java IO glob can be slow.

It is one reason why it is important to do thoses matches in a thread

@sebthom
Copy link
Copy Markdown
Member Author

sebthom commented Nov 19, 2025

Thanks for the insight!

@sebthom sebthom marked this pull request as ready for review November 19, 2025 13:54
@sebthom sebthom requested a review from rubenporras November 19, 2025 13:54
@sebthom sebthom changed the title feat: add workspace didChangeWatchedFiles support feat: add workspace/didChangeWatchedFiles support Nov 19, 2025
Comment thread org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServerWrapper.java Outdated
Comment thread org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServerWrapper.java Outdated
* Resource listener that translates Eclipse resource change events into LSP
* file watch events and dispatches them if the language server is still active
*/
private final class WatchedFilesListener implements IResourceChangeListener {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to its own class file in the internal package?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this would be very useful. The class is very specialist, not reusable elsewhere and relies on multiple internal fields of LanguageServerWrapper (dispatcher, context, fileSystemWatcherManager).

Copy link
Copy Markdown
Contributor

@angelozerr angelozerr Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be useful since LanguageServerWrapper is a big file. You could create WatchedFilesListener without modifier in the same package than LanguageServerWrapper

Copy link
Copy Markdown
Member Author

@sebthom sebthom Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For that LanguageServerWrapper is in the wrong package. I would not want to pollute the root package with a "random" WatchedFilesListener class file that is an internal listener implementation (like LSFileBufferListener or WorkspaceFolderListener) of LanguageServerWrapper. If LoC of LanguageServerWrapper is a concern we should better think about moving all the generic utility methods like getRootCauseMessage/getThrowableMessage/disconnectTextFileBuffer/supportsWorkspaceFolders etc. out of LanguageServerWrapper but I would do this in a dedicated PR focused on refactoring/cleanup of the class.

@sebthom sebthom merged commit ccff1d1 into eclipse-lsp4e:main Nov 20, 2025
10 checks passed
@sebthom sebthom deleted the issue-547 branch November 25, 2025 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for DidChangeWatchedFiles Notification

3 participants